<h3>Select Categories <span class="required">*</span></h3><hr />
<?php
if(isset($exist)==1 || isset($_GET['owner'])!=0){
	$pro_exist=1;
}else{
	$pro_exist=0;	
}
$category_array = array();
$sql3 = "SELECT category_id FROM tblproduct_in_category WHERE product_id = $id";
$result3 = mysql_query($sql3);
while ($row3 = mysql_fetch_assoc($result3)){
	$category_array[] = $row3['category_id'];
}

$sql_cat = "SELECT * FROM tblcategory WHERE parent_id = 0 AND status = 1 ORDER BY category_name";
$result_cat = mysql_query($sql_cat);
$i = 1;
while($row_cat = mysql_fetch_assoc($result_cat)){
	if($i>4){	
	$i = 1;
	}
?>
	<div style="width:150px; float:left;"><strong><?php echo $row_cat['category_name']?></strong><br />
    	<?php
		$sql_sub = "SELECT * FROM tblcategory WHERE parent_id = ".$row_cat['id']." AND status = 1 ORDER BY category_name";
		$result_sub = mysql_query($sql_sub);
		while($row_sub = mysql_fetch_assoc($result_sub)){
			$checkedcat = (in_array($row_sub['id'],$category_array))?' checked="checked"':'';
		?>
        	<input type="checkbox" name="selectcat[]" value="<?php echo $row_sub['id'];?>" <?php echo !empty($id)?$checkedcat:""?> <?php echo($pro_exist==1)?' disabled="disabled"':''?> />&nbsp; <?php echo $row_sub['category_name'];?><br />
        <?php	
		}// end sub
		?>
    </div>
<?php	
	$i++;
}// end main
?>